namespace dPet.Infrastructure.EntityFramework.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddModels : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.ServiceItem",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        Name = c.String(nullable: false, maxLength: 20),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                        Category_Id = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ServiceCategory", t => t.Category_Id)
                .Index(t => t.Category_Id);
            
            CreateTable(
                "dbo.ServiceCategory",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        HospitalId = c.String(),
                        Name = c.String(),
                        CreateTime = c.DateTime(nullable: false),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ServiceSKUProperty",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        HospitalId = c.String(nullable: false, maxLength: 32),
                        ServiceCategoryId = c.String(nullable: false, maxLength: 32),
                        FrontendName = c.String(nullable: false, maxLength: 50),
                        BackendName = c.String(nullable: false, maxLength: 50),
                        LastModified = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ServiceSKUPropertyValue",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 32),
                        Value = c.String(nullable: false, maxLength: 255),
                        LastModified = c.DateTime(nullable: false),
                        SKUProperty_Id = c.String(nullable: false, maxLength: 32),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.ServiceSKUProperty", t => t.SKUProperty_Id, cascadeDelete: true)
                .Index(t => t.SKUProperty_Id);
            
            CreateTable(
                "dbo.ServiceItemServiceSKUProperty",
                c => new
                    {
                        ServiceItem_Id = c.String(nullable: false, maxLength: 32),
                        ServiceSKUProperty_Id = c.String(nullable: false, maxLength: 32),
                    })
                .PrimaryKey(t => new { t.ServiceItem_Id, t.ServiceSKUProperty_Id })
                .ForeignKey("dbo.ServiceItem", t => t.ServiceItem_Id, cascadeDelete: true)
                .ForeignKey("dbo.ServiceSKUProperty", t => t.ServiceSKUProperty_Id, cascadeDelete: true)
                .Index(t => t.ServiceItem_Id)
                .Index(t => t.ServiceSKUProperty_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.ServiceItemServiceSKUProperty", "ServiceSKUProperty_Id", "dbo.ServiceSKUProperty");
            DropForeignKey("dbo.ServiceItemServiceSKUProperty", "ServiceItem_Id", "dbo.ServiceItem");
            DropForeignKey("dbo.ServiceSKUPropertyValue", "SKUProperty_Id", "dbo.ServiceSKUProperty");
            DropForeignKey("dbo.ServiceItem", "Category_Id", "dbo.ServiceCategory");
            DropIndex("dbo.ServiceItemServiceSKUProperty", new[] { "ServiceSKUProperty_Id" });
            DropIndex("dbo.ServiceItemServiceSKUProperty", new[] { "ServiceItem_Id" });
            DropIndex("dbo.ServiceSKUPropertyValue", new[] { "SKUProperty_Id" });
            DropIndex("dbo.ServiceItem", new[] { "Category_Id" });
            DropTable("dbo.ServiceItemServiceSKUProperty");
            DropTable("dbo.ServiceSKUPropertyValue");
            DropTable("dbo.ServiceSKUProperty");
            DropTable("dbo.ServiceCategory");
            DropTable("dbo.ServiceItem");
        }
    }
}
